package com.ad.platform.service.impl;

import com.ad.payload.dto.JielongOrderDto;
import com.ad.platform.mapper.PreOrderMapper;
import com.ad.platform.model.PreOrder;
import com.ad.platform.service.IPreOrderService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author rclia
 * @since 2021-03-10
 */
@Service
@Slf4j
public class PreOrderServiceImpl extends ServiceImpl<PreOrderMapper, PreOrder> implements IPreOrderService{

    @Autowired
    private PreOrderMapper preOrderMapper;

    @Override
    public boolean createJielongOrder(JielongOrderDto jielongOrderDto) {
        log.info("入参 ============================================ " + JSON.toJSONString(jielongOrderDto));
        PreOrder preOrder = new PreOrder();
        preOrder.setId(Long.parseLong(jielongOrderDto.getId()));
        preOrder.setJielongStarttime(LocalDateTime.parse(jielongOrderDto.getStartTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        preOrder.setJielongEndtime(LocalDateTime.parse(jielongOrderDto.getEndTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        preOrder.setPhone(jielongOrderDto.getPhone());
        preOrder.setAddress(jielongOrderDto.getAddress());
        preOrder.setIsJielong("Y");

        preOrderMapper.insert(preOrder);

        return true;
    }
}
